Skip to content

Conversation

@kullfar
Copy link

@kullfar kullfar commented Feb 20, 2015

I've found a bug in async-http-client.
1.set 'maxConnections' and 'maxConnectionsPerHost' simultaneously.
2.try to GET the same host multiple times. With channels auto-closed after each request (with no chance here: tryToOfferChannelToPool https://github.com/AsyncHttpClient/async-http-client/blob/async-http-client-1.9.10/src/main/java/com/ning/http/client/providers/netty/channel/ChannelManager.java#L285)
3.Semaphore freeChannelsForHost (here https://github.com/AsyncHttpClient/async-http-client/blob/async-http-client-1.9.10/src/main/java/com/ning/http/client/providers/netty/channel/ChannelManager.java#L142) won't be decremented on channel close and you'll get
"Caused by: java.io.IOException: Too many connections per host XXX"

Because there is no mapping in channelId2KeyPool
(https://github.com/AsyncHttpClient/async-http-client/blob/async-http-client-1.9.10/src/main/java/com/ning/http/client/providers/netty/channel/ChannelManager.java#L140)

I think it should be added here, while "registerOpenChannel" (https://github.com/AsyncHttpClient/async-http-client/blob/async-http-client-1.9.10/src/main/java/com/ning/http/client/providers/netty/channel/ChannelManager.java#L384)

prove-of-fail can be found here https://github.com/kullfar/async-test
steps to reproduce:
git clone 'https://github.com/kullfar/async-test.git'
cd async-test
mvn clean install
java -jar target/async-test-1.0-SNAPSHOT.jar

You will get "Caused by: java.io.IOException: Too many connections per host 3" line shortly

If you'll compile my pull request version and change pom.xml to use 1.9.11-SNAPSHOT version, there will be no Exceptions.

ps. It's the pull request to the 1.9.x branch (just because I use it ritgh now in prod), but as I can see 2.x branch needs to be fixed as well

@slandelle
Copy link
Contributor

2.use apache http client

You mean Netty, right?

@kullfar
Copy link
Author

kullfar commented Feb 20, 2015

sorry, completely misleading step. I mean

<dependency>
  <groupId>org.apache.httpcomponents</groupId>
  <artifactId>httpclient</artifactId>
  <version>4.3.6</version>
</dependency>

in pom.xml from prove-of-fail

have just removed it
kullfar/async-test@96fb464

just ignore ;-)

@kullfar
Copy link
Author

kullfar commented Feb 20, 2015

I've removed this step "2.use apache http client" from the pull request description

@slandelle
Copy link
Contributor

Fix seems legit, but could you add a test for it, please?

@kullfar
Copy link
Author

kullfar commented Feb 21, 2015

sure, will do.
I'll return to that on Tuesday.
Thx!

@slandelle
Copy link
Contributor

Thanks!

@slandelle slandelle changed the title fix releasing limit for connections pool per host Netty: Fix releasing limit for connections pool per host Feb 23, 2015
@slandelle
Copy link
Contributor

Adding the test myself. Thanks a lot for reporting and fixing!

slandelle pushed a commit that referenced this pull request Feb 23, 2015
Netty: Fix releasing limit for connections pool per host
@slandelle slandelle merged commit cfc9e28 into AsyncHttpClient:1.9.x Feb 23, 2015
@slandelle slandelle added this to the 1.9.11 milestone Feb 23, 2015
@slandelle slandelle self-assigned this Feb 23, 2015
slandelle added a commit that referenced this pull request Feb 23, 2015
@kullfar
Copy link
Author

kullfar commented Feb 24, 2015

Awesome! You are fast! ;-)Thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants